package com.hualan.sfzy.service.counselor.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.counselor.CounselorLeaveword;
import com.hualan.sfzy.mapper.counselor.CounselorLeavewordMapper;
import com.hualan.sfzy.service.counselor.CounselorLeavewordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("CounselorLeavewordService")
public class CounselorLeavewordServiceImpl implements CounselorLeavewordService {
    @Autowired
    private CounselorLeavewordMapper counselorLeavewordMapper;

    @Override
    public int add(CounselorLeaveword entity) {
        return counselorLeavewordMapper.insert(entity);
    }

    @Override
    public int remove(Integer id) {
        return counselorLeavewordMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return counselorLeavewordMapper.deleteBatch(ids);
    }

    @Override
    public int edit(CounselorLeaveword counselorLeaveword) {
        return counselorLeavewordMapper.update(counselorLeaveword);
    }

    @Override
    public List<CounselorLeaveword> find() {
        return counselorLeavewordMapper.select(null);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, CounselorLeaveword entity) {
        PageHelper.startPage(pageNum, pageSize);

        List<CounselorLeaveword> list = counselorLeavewordMapper.select(entity);

        PageInfo<CounselorLeaveword> PageInfo = new PageInfo<>(list);

        Map<String, Object> map = new HashMap<>();

        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.PAGE_TOTAL,PageInfo.getPages());
        map.put(CommonConstant.TOTAL,PageInfo.getTotal());

        return map;
    }

    @Override
    public CounselorLeaveword findById(Integer id) {
        return counselorLeavewordMapper.selectById(id);
    }


}
